This disclosure relates generally to databases of computer systems and, more particularly, relates to reorganizing a table according to one or more queries. Databases use tables to organize information. Each table consists of a number of rows, each of which corresponds to a single database record. Keys are used to organize the database. Each database table has one or more columns designated as the primary key. The value of this key is unique for each record in the database. Database tables are traditionally organized physically on a storage medium (such as a hard disk).